<template>
	<view>
		<view class="formgroup_upImage  inputtext">
			<view class="border-bottom-E3E3E5" style="padding-bottom: 20rpx;">
				<view class="labletitle" v-if="showLabel" style="margin-left: 40rpx;">
					<label>{{label}}</label>
					<text class="required" v-show="required">*</text>
				</view>
				<!-- <upload-annx :model="vModel" :upImgConfig="upImgBasic" @onUpImg="upBasicData"/> -->
				<u-upload :max-size="fileSize*1024*1024"
				 :max-count="limit"
				 :file-list="fileList"
				 v-model="valueTitle"
				:action="action"
				ref="uUpload"
				@on-remove="onRemove"
				:deletable='deletable'
				:show-progress= 'showProgress'
				:Status='Status'
				@on-uploaded='onUploaded'></u-upload>
			</view>
		</view>
	</view>
</template>

<script>
	
	import config from '@/common/js/config.js'
	let apiKey = uni.getStorageSync('apiKey') || 'api';
	let baseUrl = config.Global.baseUrl[apiKey].apiUrl;
	export default {
		props:{
			value:'',
			limit:{
				type:Number,
				default(){
					return 9
				}
			},
			fileSize:{
				type:Number,
				default(){
					return 2
				}
			},
			showLabel:{
				type:Boolean,
				default(){
					return true
				}
			},
			label:{
				type:String,
				default(){
					return '图片上传'
				}
			},
			vModel:{
				type:String,
				default(){
					return ''
				}
			},
			required:{
				type:Boolean,
				default(){
					return false
				}
			},
		},
		data() {
			return {
				valueTitle:'',
				fileList:[],
				action: baseUrl+"/api/Common/Uploader/annexpic",
				showUploadList: false,
				upLoadImgList:[],
				deletable:true,
				Status:0,
				showProgress:false
			};
		},
		created() {
			//动态显示图片删除按钮
			let Status = uni.getStorageSync('F_Status');
			if(Status){
				this.Status = Status
				if(this.Status == 1){
					this.deletable = false
				}
			}
		},
		watch:{
			value(val){
				console.log(val)
				this.fileList = val;
			}
		},
		
		methods:{
			onRemove(index,lists){
				this.valueTitle = lists;
				this.handel(this.valueTitle)
			},
			
			onUploaded(lists, name){
				this.valueTitle = lists
				this.handel(this.valueTitle)
			},
			
			handel(lists){
				let url;
				for(let i = 0;i<lists.length;i++){
					if(lists[i].response){
						lists[i].url = baseUrl+lists[i].response.data.url
					}
				}
				this.$emit('input',lists)
			}
		
		}
	}
</script>

<style>

</style>
